package com.fa.controller;

import com.fa.common.annotation.Anonymous;
import com.fa.common.core.controller.BaseController;
import com.fa.common.core.domain.AjaxResult;
import com.fa.common.core.page.TableDataInfo;
import com.fa.common.utils.poi.ExcelUtil;
import com.fa.domain.MdVendor;
import com.fa.service.IMdVendorService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/maindata/vendor")
public class MdVendorController extends BaseController {

    @Autowired
    private IMdVendorService mdVendorService;

    /**
     * 查询供应商列表
     */
@Anonymous
    @GetMapping("/list")
    public TableDataInfo list(MdVendor mdVendor)
    {
        startPage();
        List<MdVendor> list = mdVendorService.selectMdVendorList(mdVendor);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, MdVendor mdVendor)
    {
        List<MdVendor> list = mdVendorService.selectMdVendorList(mdVendor);
        ExcelUtil<MdVendor> util = new ExcelUtil<MdVendor>(MdVendor.class);
        util.exportExcel(response, list, "供应商数据");
    }

    /**
     * 获取供应商详细信息
     */
@Anonymous
    @GetMapping(value = "/{vendorId}")
    public AjaxResult getInfo(@PathVariable("vendorId") Long vendorId)
    {
        return success(mdVendorService.selectMdVendorByVendorId(vendorId));
    }

    /**
     * 新增供应商
     */

    @PostMapping
    public AjaxResult add(@RequestBody MdVendor mdVendor)
    {
        return toAjax(mdVendorService.insertMdVendor(mdVendor));
    }

    /**
     * 修改供应商
     */
@Anonymous
@PostMapping(value = "/{vendorId}")
    public AjaxResult edit(@PathVariable int vendorId, @RequestBody MdVendor mdVendor )
    {
        System.out.println(vendorId);
        System.out.println(mdVendor);
        return toAjax(mdVendorService.updateMdVendor(mdVendor));
    }

    /**
     * 删除供应商
     */
@Anonymous
    @DeleteMapping("/{vendorIds}")
    public AjaxResult remove(@PathVariable Long[] vendorIds)
    {
        return toAjax(mdVendorService.deleteMdVendorByVendorIds(vendorIds));
    }

}
